# #Lagos download script
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'), crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha') + mapview(minnesota)
Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)
#Plot all the states to check if they loaded
#mapview(states)
iowa <- states %>%
filter(name == 'Iowa') %>%
st_transform(2163)
illinois <- states %>%
filter(name == 'Illinois') %>%
st_transform(2163)
mapview(illinois, alpha.regions = 0.4, aplha = 1, col.regions = "yellow") +
mapview(iowa, alpha.regions = 0.4, aplha = 1, col.regions = "red")
#Subset lakes based on spatial position
iowa_lakes <- spatial_lakes[iowa,]
#Plotting the first 1000 lakes
mapview(iowa, alpha.regions = 0.4, aplha = 1, col.regions = "red") +
iowa_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
#Subset lakes based on spatial position
illinois_lakes <- spatial_lakes[illinois,]
#Plotting the first 1000 lakes
mapview(illinois, alpha.regions = 0.4, aplha = 1, col.regions = "yellow") +
illinois_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
Subset LAGOS data to these sites, how many sites are in Illinois and Iowa combined? How does this compare to Minnesota?
minnesota_length = length(minnesota_lakes$lagoslakeid)
iowa_illinois_lakes = rbind(illinois_lakes, iowa_lakes)
iowa_illinois_length = length(iowa_illinois_lakes$lagoslakeid)
Minnesota has 29038 lakes while Iowa & Illinois combined have 16466 lakes
Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
ggplot(minnesota_lakes, aes(x= lake_area_ha)) +
geom_histogram() +
scale_x_log10(labels = scales::comma)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Make an interactive plot of lakes in Iowa and Illinois and color them by lake area in hectares
iowa_illinois_map = iowa_illinois_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:100000) %>%
mapview(.,zcol = 'lake_area_ha', canvas = TRUE)
mapview(illinois, canvas = TRUE , alpha.regions = 0.4, aplha = 1, col.regions = "yellow") +
mapview(iowa, canvas = TRUE , alpha.regions = 0.4, aplha = 1, col.regions = "red") +
iowa_illinois_map